const { list } = require('./src/mock')
const bodyParser = require('body-parser')
const data = [{ user: '张三', pwd: "123" }, { user: 'admin', pwd: '666' }]
module.exports = {
  devServer: {
    before(app) {
      app.use(bodyParser.json())

      app.get('/list', (req, res) => {
        res.send({
          code: 200,
          data: list
        })
      })

      app.post('/api/login', (req, res) => {
        const { user, pwd } = req.body;
        const o = data.find(item => item.user === user && item.pwd === pwd)

        if(o) {
          res.send({
            code: 200,
            mess: '登录成功',
            token: user
          })
        } else {
          res.send({
            code: 401,
            mess: '账户密码错误',
          })
        }
      })
    }
  }
}